package com.example.demo.controller;


import com.example.demo.entity.Areas;
import com.example.demo.entity.Employee;
import com.example.demo.entity.Users;
import com.example.demo.entity.UsersDto;
import com.example.demo.service.UserService;
import com.example.demo.utils.PageDataList;
import com.example.demo.utils.ResultUtil;
import com.example.demo.utils.SendSms;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {

  @Autowired
  private UserService userService;

  @Autowired
  private SendSms sendSms;

  @PostMapping("/userLogin")
  @ResponseBody
  public ResultUtil userLogin(HttpSession session, @RequestBody  Users input) {
    ResultUtil resultUtil = userService.userLogin(session,input);
    return resultUtil;
  }

  @PostMapping("/list")
  @ResponseBody
  public ResultUtil getList(@RequestBody UsersDto users) {
    PageDataList<Users> resultList = userService.getList(users);
    ResultUtil resultUtil = new ResultUtil();
    if (resultList != null) {
      resultUtil.setResultCode("200");
      resultUtil.setResultMsg("请求成功");
      resultUtil.setResultData(resultList);
    } else {
      resultUtil.setResultCode("201");
      resultUtil.setResultMsg("请求失败");
    }
    return resultUtil;
  }

  @GetMapping("queryUserById")
  @ResponseBody
  public Users query(String id) {
    UsersDto usersDto = new UsersDto();
    usersDto.setId(Integer.parseInt(id));
    Users users = userService.queryUserById(usersDto);
    return users;
  }


  @GetMapping("deleteUserById")
  @ResponseBody
  public String deleteUserById(String id) {
    UsersDto usersDto = new UsersDto();
    usersDto.setId(Integer.parseInt(id));
    String result = userService.deleteUserById(usersDto);
    return result;
  }




}
